<template>
    <div>
       <h3>登录</h3>
       <table class="table">
        <thead>
            <tr>
                <th>账号</th>
                <th><input type="text" v-model="logindata.name"></th>
            </tr>
            <tr>
                <th>密码</th>
                <th><input type="password" v-model="logindata.pwd"></th>
            </tr>
            <tr>
                <th colspan="2">
                    <input type="button" value="登录" @click="Login">
                </th>
            </tr>
        </thead>
       </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { UserStore } from '@/stores/user';
import { useRouter } from 'vue-router';
const router=useRouter()

const user=UserStore()
const logindata=ref({
    name:'',
    pwd:''
})
const Login=()=>{
    axios.get('/api/Student/Login',{params:logindata.value}).then(res=>{
        if(res.data.studentId==-1)
    {
        alert('账号不存在')
        return;
    }
     if(res.data.studentId==-2)
    {
        alert('密码错误')
        return;
    }
     if(res.data.studentId>0)
    {
         alert('登录成功')
        user.userdata.username=logindata.value.name
        user.userdata.islogin=true
        sessionStorage.setItem("islogin","true")
        router.push('/')
    }

    })
}

</script>

<style scoped>

</style>